<template>
	<!-- 我的康复师 -->
	<view style="		
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;">
		<!-- <view> -->
		<my-card-member :title1="memberName" title2="会员" title3="我的顾问" :title4="recureAdviserName" title5="套餐一" title6="../static/logo.png" style="z-index: 100;"></my-card-member>
		<view style="
			width: 641rpx;
			height: 341rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 11rpx 14rpx 0rpx #E9F7ED;
			border-radius: 29rpx;
			padding: 38rpx 33rpx;
			display: flex;
			flex-direction: column;
			justify-content: flex-end;
			margin-top: -120rpx;">
			<my-task :list="list" :num="num"></my-task>
		</view>
		<view style="		
			width: 100%;
			background: #fff;
			box-shadow: 0rpx 11rpx 14rpx 0rpx #E9F7ED;
			border-radius: 45rpx 45rpx 0rpx 0rpx;
			margin-top: 25rpx;
			box-sizing: border-box;
			padding: 30rpx 24rpx;">
			<my-class></my-class>
		</view>
	</view>
</template>

<script>
	import myCardMember from "@/components/my-card-member.vue"
	import myTask from "@/components/my-task-member.vue"
	import myClass from "@/components/my-class-member.vue"
	export default {
		name: "myMember",
		components: {
			myCardMember,
			myTask,
			myClass
		},
		data() {
			return {
				num: 12,
				memberName: "",
				recureAdviserName: "暂无",
				list: [{
					icon: "/static/icon/all.png",
					name: "全部",
					num: 0,
				}, {
					icon: "/static/icon/waitClass.png",
					name: "待上课",
					num: 0,
				}, {
					icon: "/static/icon/completed.png",
					name: "已完成",
					num: 0,
				}]
			}
		},
		onLoad() {

		},
		mounted() {
			this.memberClassCount();
			this.memberDetail();
		},
		methods: {
			reLoadFn() {
				//刷新数据逻辑
				this.memberClassCount();
				this.memberDetail();
			},
			memberClassCount() {
				let that = this;
				uni.request({
					url: "https://guokang365.mordo-care.com/api/custom/countLessonNumByMemberId/" + getApp().globalData.memberId,
					method: 'GET',
					//仅为示例，并非真实接口地址。
					header: {
						'Cookie': "JSESSIONID=" + getApp().globalData.serverSession
						// 'JSESSIONID': getApp().globalData.serverSession //自定义请求头信息
					},
					success: (res) => {
						if (res.data.result != '100') {
							// 获取会员统计数据失败，不确定是否要弹窗
						} else {
							let countData = res.data;
							let list2 = that.list;
							list2[0].num = countData.totalNum;
							list2[1].num = countData.toBeCompletedNum;
							list2[2].num = countData.finishedNum;
							that.list = list2
						}
					},
				});
			},
			memberDetail() {
				// todo 需要改成级联形式，获取orderList
				let that = this;
				uni.request({
					url: "https://guokang365.mordo-care.com/api/member/findCascade/" + getApp().globalData.memberId,
					method: 'POST',
					//仅为示例，并非真实接口地址。
					header: {
						'Cookie': "JSESSIONID=" + getApp().globalData.serverSession
						// 'JSESSIONID': getApp().globalData.serverSession //自定义请求头信息
					},
					data: {
						"cascades": [{
							"column": "orderList",
						}],
					},
					success: (res) => {
						// todo 需要使用级联查询，查套餐名
						if (res.data.result != '100') {
							// 获取会员详情失败，不确定是否要弹窗
						} else {
							that.memberName = res.data.entity.name;
							getApp().globalData.memberName = res.data.entity.name;
							if (res.data.entity.recureAdviserName != null && res.data.entity.recureAdviserName != '') {
								that.recureAdviserName = res.data.entity.recureAdviserName;
							}
						}
					},
				});
			},
			getServiceName(list) {
				if (list.length === 0) {
					// 处理空数组的情况
					return "";
				}

				const maxOrderTimeItem = list.reduce((prev, current) => {
					return prev.orderTime > current.orderTime ? prev : current;
				});

				const serviceName = maxOrderTimeItem.serviceName;
				return serviceName;
			},
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

	}

	.taskCard {
		width: 641rpx;
		height: 341rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 11rpx 14rpx 0rpx #E9F7ED;
		border-radius: 29rpx;
		padding: 38rpx 33rpx;
		display: flex;
		flex-direction: column;
		justify-content: flex-end;
		margin-top: -120rpx;
	}

	.class-card {
		width: 100%;
		background: #fff;
		box-shadow: 0rpx 11rpx 14rpx 0rpx #E9F7ED;
		border-radius: 45rpx 45rpx 0rpx 0rpx;
		margin-top: 25rpx;
		box-sizing: border-box;
		padding: 30rpx 24rpx;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>